import { ElMessage, ElMessageBox } from 'element-plus'
import { useStore } from '@/stores'
type MessageType = 'success' | 'warning' | 'info' | 'error'

export const messages = (message: string, type: MessageType = 'info') =>
    ElMessage({
        showClose: true,
        message,
        type
    })
// 确认消息
export const confirms = (
    message = '确认删除吗？',
    title = '删除提示',
    confirmButtonText = '确定',
    cancelButtonText = '取消'
) => {
    return new Promise((resolve) => {
        ElMessageBox.confirm(message, title, {
            confirmButtonText,
            cancelButtonText,
            type: 'warning'
        })
            .then(() => {
                resolve(true)
            })
            .catch(() => {
                console.log('取消')
            })
    })
}

export const getPageSize = () => {
    const store = useStore()
    return store.pageSize
}

// 判断当前设备
export const isMobile = (): boolean => {
    const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
    const isSmallScreen = window.innerWidth <= 768
    return isMobile || isSmallScreen
}

// 拷贝链接
export const copyLink = (url: string) => {
    // navigator.clipboard.writeText(`${shareLink.value} 提取码: ${extractionCode.value}`);
    navigator.clipboard.writeText(url)
}
